package com.ezjie.login.widget;

import com.ezjie.baselib.util.OnDialogBtnClickImpl;
import com.ezjie.login.R;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * app内提醒对话框
 * @author renyangyang
 *
 */
public class AppWarnDialog extends Dialog {

	private TextView tv_content;
	private LinearLayout ll_layout1;
	private LinearLayout ll_layout2;
	private Button btn_yes;
	private Button btn_no;
	private Button btn_know;
	/**
	 * 下面是一个按钮，还是2个按钮  true为一个按钮
	 */
	private boolean isOneButton;
	
	private OnDialogBtnClickImpl listener;
	
	private Context context;
	public AppWarnDialog(Context context) {
		super(context);
		this.context = context;
		init();
	}
	
	
	public AppWarnDialog(Context context, int theme) {
		super(context, theme);
		this.context = context;
		init();
	}


	private void init(){
		View view = LayoutInflater.from(context).inflate(R.layout.layout_app_dialog,
				null);
		this.setCanceledOnTouchOutside(false);
    	this.setContentView(view);
    	
    	tv_content = (TextView) view.findViewById(R.id.tv_content);
    	ll_layout1 = (LinearLayout) view.findViewById(R.id.ll_layout1);
    	ll_layout2 = (LinearLayout) view.findViewById(R.id.ll_layout2);
    	btn_yes = (Button) view.findViewById(R.id.btn_yes);
    	btn_no = (Button) view.findViewById(R.id.btn_no);
    	btn_know = (Button) view.findViewById(R.id.btn_know);
    	
    	btn_yes.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (listener != null) {
					AppWarnDialog.this.cancel();
					listener.onYesClick();
				}
			}
		});
    	btn_no.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (listener != null) {
					AppWarnDialog.this.cancel();
					listener.onNoClick();
				}
			}
		});
    	btn_know.setOnClickListener(new View.OnClickListener() {
	
			@Override
			public void onClick(View v) {
				if (listener != null) {
					AppWarnDialog.this.cancel();
					listener.onKnowClick();
				}
			}
		});
	}

	public boolean isOneButton() {
		return isOneButton;
	}

	public void setOneButton(boolean isOneButton) {
		this.isOneButton = isOneButton;
		if (isOneButton) {
    		ll_layout1.setVisibility(View.GONE);
        	ll_layout2.setVisibility(View.VISIBLE);
		}else {
			ll_layout1.setVisibility(View.VISIBLE);
	    	ll_layout2.setVisibility(View.GONE);
		}
	}

	/**
	 * 设置内容
	 * @param message
	 */
	public void setMessage(String message) {
		tv_content.setText(message);
	}
	public void setMessage(int resId) {
		tv_content.setText(resId);
	}

	/**
	 * 设置确定按钮内容
	 * @param yesButton
	 */
	public void setYesButton(String yesButton) {
		btn_yes.setText(yesButton);
	}
	public void setYesButton(int resId) {
		btn_yes.setText(resId);
	}
	/**
	 * 设置取消按钮内容
	 * @param yesButton
	 */
	public void setNoButton(String noButton) {
		btn_no.setText(noButton);
	}
	public void setNoButton(int resId) {
		btn_no.setText(resId);
	}
	/**
	 * 设置知道了按钮内容
	 * @param yesButton
	 */
	public void setKnowButton(String knowButton) {
		btn_know.setText(knowButton);
	}
	public void setKnowButton(int resId) {
		btn_know.setText(resId);
	}


	public void setListener(OnDialogBtnClickImpl listener) {
		this.listener = listener;
	}

	
	
}